/* Create figures 1 and 2 */
#delimit';'
set more off;

/* Read in data */
use "ss_figure1_data.dta";

sum;
list, noobs;


keep if year>=1980;
/* Public Assistance flag is off pre-1982 so make these values missing */
replace paw_impute = . if year<=1981;

/* Expand the dataset to have one observation per year per imputed measure */
/* Each measure should then have one variable  */
expand 6; /* IF CHANGING NUMBER OF MEASURES IN FIGURE, NEED TO CHANGE THIS NUMBER!!!!! */
sort year;

/* For each year, take the mod of dividing by the number of figures in the graph */
/* 0=wage_impute 1=ss_impute 2=paw_impute 3=ssi_impute 4=uc_impute 5=wc_impute  */
gen outcome_num = mod(_n,6);

gen figvalue = .;

for any wage_impute ss_impute paw_impute ssi_impute uc_impute wc_impute  \ num 0/5:
    replace figvalue = X if outcome_num==Y
    ;

for num 0/5: list year figvalue if outcome_num==X;


/* Graph the imputed values */
label define outcome_label 0 "A. Earnings" 1 "B. Social Security"
                           2 "C. AFDC/TANF" 3 "D. Supplemental Security Inc."
                           4 "E. Unemployment Insurance" 5 "F. Worker's Compensation";
label values outcome_num outcome_label;
label variable year "Year";
 
scatter figvalue year, 
        by(outcome_num, yrescale xrescale note("") /* title("No title - use latex") */
                        plotregion(color(white)) plotregion(icolor(white)) plotregion(ifcolor(white))
                        plotregion(fcolor(white)) plotregion(ilcolor(white)) plotregion(lcolor(white))
                        graphregion(color(white)) graphregion(icolor(white)) graphregion(ifcolor(white)) 
                        graphregion(fcolor(white)) graphregion(ilcolor(white)) graphregion(lcolor(white)))
        /* Set the ifcolor and ilcolor are for inner graph region while fcolor and lcolor are for outer graph region */
        /* Also fcolor and ifcolor are the fill color with lcolor and ilcolor are the border colors for the regions */
        /* NEED TO DO WITHIN THE BY STATEMENT */
        c(l) lp(l) msymbol(i)
        xtitle("Year") ytitle("Share Imputed") xlabel(1980(10)2013) ylabel(.15(.05).35) 
        subtitle(, bcolor(white)) /* MAKES COLORS OF SUBTITLES ABOVE EACH SUBFIGURE WHITE */
                                  /* NEED THE COMMA SINCE BCOLOR IS AN OPTION OF SUBTITLE!! */
        name(figure1, replace)
        ;

graph export "figure1.pdf", name(figure1) replace;


clear;


/* Read in data */
use "ss_figure2_data.dta";

sum;
list;

/* Create labels for the legend */
label variable inst "Instrument";
label variable ssinc_non_impute "S.S. Income: Non-Imputed";
label variable ssinc_impute "S.S. Income: Imputed";
label variable yobh "Year of Birth";


/* Create figure 2 */
keep if yobh<=1930;

twoway (scatter inst yobh, c(l) msymbol(i) yaxis(2))
       (scatter ssinc_non_impute ssinc_impute yobh, 
                c(l l) msymbol(i i) lpattern(dash shortdash) yaxis(1) ytitle("Reported S.S. Income")),
                        plotregion(color(white)) plotregion(icolor(white)) plotregion(ifcolor(white))
                        plotregion(fcolor(white)) plotregion(ilcolor(white)) plotregion(lcolor(white))
                        graphregion(color(white)) graphregion(icolor(white)) graphregion(ifcolor(white)) 
                        graphregion(fcolor(white)) graphregion(ilcolor(white)) graphregion(lcolor(white))
        /* Set the ifcolor and ilcolor are for inner graph region while fcolor and lcolor are for outer graph region */
        /* Also fcolor and ifcolor are the fill color with lcolor and ilcolor are the border colors for the regions */
        /* NEED TO DO WITHIN THE BY STATEMENT */
       name(figure2, replace);

graph export "figure2.pdf", name(figure2) replace;
